var base = require('../../utils/base.js')
var app = getApp()
var page = 1
var diffculty = []
var diffcultyTitle= []
var dance = []
var danceTitle= []
var scence = []
var scenceTitle = []
var tagsId = []
Page({
  data: {
    list: {},
    diffculty:{},
    diffcultyTitle: {},
    dance:{},
    danceTitle: {},
    scence:{},
    scenceTitle: {},
    video:'',
    width:0
  },
  onReady: function () {
    var that = this
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          width: res.windowWidth
        })
      }
    })
    
    this.loadTags()
  },
  //下拉刷新
  onPullDownRefresh: function () {

    this.loadData()

  },
  loadTags(){
    var that = this
    base.getJson('TeachClassAlbum/teachClassAlbumTagsList', null, function (data) {
      console.log(data)
      
      for (var i = 0; i < data.teachClassAlbumTags.length;i++){
        if (data.teachClassAlbumTags[i].type==1){
          diffculty.push(data.teachClassAlbumTags[i])
          diffcultyTitle.push(data.teachClassAlbumTags[i].title)
        } else if (data.teachClassAlbumTags[i].type == 2){
          dance.push(data.teachClassAlbumTags[i])
          danceTitle.push(data.teachClassAlbumTags[i].title)
        }else{
          scence.push(data.teachClassAlbumTags[i])
          scenceTitle.push(data.teachClassAlbumTags[i].title)
        }
      }
      // console.log(dance)
      that.setData({
        diffcultyTitle: diffcultyTitle,
        danceTitle: danceTitle,
        scenceTitle: scenceTitle
      })
      that.loadData()
    })
  },
  loadData(status) {
    if (status) {
      page++
    } else {
      page = 1
    }
    var that = this
    
    base.getJson('TeachClassAlbum/teachClassAlbumTags', { row: page * 10, tags_id: tagsId }, function (data) {
      console.log(data)
      that.setData({
        list: data.teachClassAlbums
      })
      page += 1
    })

  },
  onReachBottom: function () {
    this.loadData(1)
  },
  //设置分享
  onShareAppMessage: function () {
    return {
      title: '每日最新舞蹈视频尽在酱游舞蹈',
      desc: '每日最新舞蹈视频',
      path: '/pages/video/videoList'
    }
  },
  bindDiffcultyChange:function(e){
    var val = e.detail.value
    tagsId = []
    tagsId.push(diffculty[val].id)
    this.loadData()
  },
  bindDanceChange: function (e) {
    var val = e.detail.value
    tagsId = []
    tagsId.push(dance[val].id)
    this.loadData()
  },
  bindScenceChange: function (e) {
    var val = e.detail.value
    tagsId = []
    tagsId.push(scence[val].id)
    this.loadData()
  },
  all: function () {
    tagsId = []
    this.loadData()
  },
  playVideo:function(e){
    console.log(e)
    var url = e.currentTarget.dataset.video
    this.setData({
      video: url
    })
  },
  closeVideo:function(e){
    this.setData({
      video: ''
    })
  },
  // 播放结束弹出框
  playEnd: function () {
    wx.showModal({
      title: '感谢观看',
      content: '完整视频请下载街舞酱APP，加客服微信jam1702更有千元礼包等你拿哦，点击“确定”进入APP下载二维码页面',
      success: function (res) {
        if (res.confirm) {
          console.log('用户点击确定')
          wx.navigateTo({
            url: 'classDetail',
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })
  }
})